package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.BillDetailEnergy;
import com.juyu.miliao.api.domain.EnergyLevel;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class EnergyLevelDao {
    @Resource
    private SqlSession sqlSession;


    public List<EnergyLevel> getUserEnergyLevelList() {
        return sqlSession.selectList("getUserEnergyLevelList");
    }

    public List<EnergyLevel> getLevelInfoList() {
        return sqlSession.selectList("getLevelInfoList");
    }

    public int insertBillDetailEnergy(long userId, int energyType, int energy) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("energyType", energyType);
        params.put("energy", energy);
        return sqlSession.insert("insertBillDetailEnergy",params);
    }

    public List<BillDetailEnergy> getUserBillDetailEnergy(long userId, int startNum, Integer pageSize) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("startNum", startNum);
        params.put("pageSize", pageSize);
        return sqlSession.selectList("getUserBillDetailEnergy",params);
    }

    public EnergyLevel selectEnergyLevelInfoByEnergyGrade(int energyGrade){
        return sqlSession.selectOne("selectEnergyLevelInfoByEnergyGrade",energyGrade);
    }


}
